<!DOCTYPE html>
<html lang="zh-cmn-Hans">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<title>ChinaBang Awards 2017</title>
		<link rel="stylesheet" href="../style/weui.css" />
		<link rel="stylesheet" href="./example.css" />
	</head>

	<body ontouchstart>
		<div class="weui-toptips weui-toptips_warn js_tooltips">错误提示</div>

		<div class="container" id="container"></div>

		<script type="text/html" id="tpl_home">
			<div class="page">
				<div class="page__hd">
					<h1 class="page__title">
           				 <img src="./images/logo.png" alt="ChinaBang" height="21px" />
       				 </h1>
					<p class="page__desc">ChinaBang Awards 一直以「发现中国创新的力量」为宗旨，积极在全中国范围内搜寻最有潜力，最有价值的创业项目，力求打造行业内最权威的评选盛会。</p>
				</div>
				<div class="page__bd page__bd_spacing">
					<ul id="bigCategory">
					</ul>
				</div>
				
				<div class="weui-msg__extra-area" style="position: relative; margin-top: 10%;">
					<div class="weui-footer">
						<p class="weui-footer__links">
							<a href="javascript:void(0);" class="weui-footer__link" id="index_page">前往 ChinaBang Awards 2017 官网了解详情</a>
						</p>
						<p class="weui-footer__text">Copyright &copy; 2017 TechNode</p>
					</div>
				</div>
						
				<!--<div class="page__ft">
					<p class="weui-footer__links">
						<a href="javascript:void(0);" class="weui-footer__link">回到首页</a>
					</p>
					<a href="javascript:home()"><img src="./images/icon_footer.png" /></a>
				</div>-->
			</div>
			<input id="gimg" type="hidden" value="http://angelnode.qiniudn.com/18d0d795cd31493bb7850e6a41ee3c7d.jpg?imageView2/1/w/169/h/169">
			<input id="title" type="hidden" value="ChinaBang Awards 2017 年度评选">
			<input id="desc" type="hidden" value="发现中国创新力量">
		
		
			<script type="text/javascript">
				$(function() {
					var winH = $(window).height();
					var categorySpace = 10;
					var voterId = localStorage.getItem("voterId");
					var accessToken = localStorage.getItem("accessToken");
					/*var sharedVoterId = utils.getUrlParam("sharedVoterId");
					var sharedAccessToken = utils.getUrlParam("sharedAccessToken");*/
					if(!voterId || !accessToken) {
						var link_ = getWeChatUrl();
						window.location.href = link_;
						return;
					}  /*else if(sharedVoterId && sharedAccessToken) {
						localStorage.setItem("voterId", sharedVoterId);
						localStorage.setItem("accessToken", sharedAccessToken);
						voterId = sharedVoterId;
						accessToken = sharedAccessToken;
					}*/
						$("#index_page").on("click", function () {
							window.location.href = "http://chinabang.technode.com/2017/";
						});
						var url = restUrls.vote.getCategoryList + "?voterId=" + voterId + "&accessToken=" + accessToken;
						$.post(url, {}, function(result) {
							if(result.errorCode == 0) {
								if(result.data && result.data.rsData) {
									for(var i = 0; i < result.data.rsData.length; i++) {
										var li = $("<li></li>");
										var div = '<div class="weui-flex js_category"><p class="weui-flex__item">' + result.data.rsData[i].name + '</p><img src="./images/icon_nav_form.png" alt=""></div>';
										var categoryList = result.data.rsData[i].categoryList;
										var categoryInnerDiv = "";
										if(categoryList) {
											var categoryInnerList = "";
											for(var j = 0; j < categoryList.length; j++) {
												categoryInnerList += '<a class="weui-cell weui-cell_access js_item" data-id=\"' + categoryList[j].id + '\" href="javascript:;">' +
													'<div class="weui-cell__bd">' +
													'<p class="category_title">' + categoryList[j].name + '</p>' +
													'</div>' +
													'<div class="weui-cell__ft"></div>' +
													'</a>';
											}
											categoryInnerDiv = '<div class="page__category js_categoryInner">' +
												'<div class="weui-cells page__category-content">' +
												categoryInnerList +
												'</div>' +
												'</div>';
	
										}
	
										li.append(div);
										li.append(categoryInnerDiv);
										$("#bigCategory").append(li);
									}
	
									$('.js_item').on('click', function() {
										var title = $(this).find(".category_title").html();
										window.location.href = 'item.html?categoryId=' + $(this).attr('data-id')+"&title="+title;
									});
									$('.js_category').on('click', function() {
										var $this = $(this),
											$inner = $this.next('.js_categoryInner'),
											$page = $this.parents('.page'),
											$parent = $(this).parent('li');
										var innerH = $inner.data('height');
										bear = $page;
	
										if(!innerH) {
											$inner.css('height', 'auto');
											innerH = $inner.height();
											$inner.removeAttr('style');
											$inner.data('height', innerH);
										}
	
										if($parent.hasClass('js_show')) {
											$parent.removeClass('js_show');
										} else {
											$parent.siblings().removeClass('js_show');
	
											$parent.addClass('js_show');
											if(this.offsetTop + this.offsetHeight + innerH > $page.scrollTop() + winH) {
												var scrollTop = this.offsetTop + this.offsetHeight + innerH - winH + categorySpace;
	
												if(scrollTop > this.offsetTop) {
													scrollTop = this.offsetTop - categorySpace;
												}
	
												$page.scrollTop(scrollTop);
											}
										}
									});
								}
							} else if(result.errorCode == 30001) { 
								weui.alert("参数错误");
							} else if(result.errorCode == 90000) {
								weui.alert("请求失败");
							}
						}, "json");
						
						
						$.ajax({
							type: "post",
							url: restUrls.vote.getConfig,
							data:{pageUrl:location.href.split('#')[0]},
							success: function(result) {
								if(result.data && result.data.rsData) {
									var wxConfig = result.data.rsData[0];
									$("#appId").val(wxConfig.appId);
									$("#timestamp").val(wxConfig.timestamp);
									$("#nonceStr").val(wxConfig.noncestr);
									$("#signature").val(wxConfig.signature);
									
									wx.config({
										appId: wxConfig.appId, // 必填，公众号的唯一标识
										timestamp: wxConfig.timestamp, // 必填，生成签名的时间戳
										nonceStr: wxConfig.noncestr, // 必填，生成签名的随机串
										signature: wxConfig.signature, // 必填，签名，见附录1
										jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
									});
									
									wx.ready(function() {
										var strurl = location.href.split('#')[0];
										var gimg = $("#gimg").val();
										var desc = $("#desc").val();
										var title = $("#title").val();
										wx.onMenuShareTimeline({
											title: title,
											desc: desc,
											link: strurl,
											imgUrl: gimg,
											trigger: function(res) {},
											success: function(res) {
												addShareRecord(itemId);
											},
											cancel: function(res) {
												// alert("已取消");
											},
											fail: function(res) {
												alert(JSON.stringify(res));
											}
										});
			
										wx.onMenuShareAppMessage({
											title: title,
											desc: desc,
											link: strurl,
											imgUrl: gimg,
											trigger: function(res) {},
											success: function(res) {
												addShareRecord(itemId);
											},
											cancel: function(res) {
												//alert("已取消");
											},
											fail: function(res) {
												alert(JSON.stringify(res));
											}
										});
									});
									
									wx.error(function(res) {
										alert(res.errMsg);
									});
								}
							}
						});
				})	
				function getImageUrl(imgName) {
					if(imgName == undefined || imgName == '') {
						return "";
					} else {
						return "http://angelnode.qiniudn.com/" + imgName + "?imageView2/1/w/169/h/169";
					}
				}	
				
				function getWeChatUrl() {
					return restUrls.indexPageShare;
				}
			</script>
			<script src="zepto.min.js"></script>
			<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
			<script src="./weui.min.js"></script>
			<script src="./example.js"></script>
			<script src="js/util/utils.js"></script>
			<script src="js/util/configs.js"></script>
			<script src="js/util/restUrls.js"></script>
	</body>

</html>